<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 子类继承父类
        class Person {
            constructor(name, sex) {
                    this.name = name;
                    this.sex = sex;
                    // 每次new都会新建一份
                    this.say = function() {
                        console.log('say');
                    };
                }
                // 共享
            speak() {
                console.log('speak');
            }
            static speak() {
                console.log('static');
            }
        }
        // 类的属性
        Person.version = '1.0';
        class Programmer extends Person {
            constructor(name, sex) {
                super(name, sex)
            }
        }
        const zs = new Programmer('zs', 'male');
        console.log(zs.name);
        console.log(zs.sex);
        zs.speak();
        Programmer.speak();
        console.log(Programmer.version);
        // 改写继承的属性和方法：同名覆盖
        class Doctor extends Person {
            constructor(name, sex, feature) {
                    // this操作不能添加到super前面
                    super(name, sex)
                    this.feature = feature
                }
                // 同名覆盖
            speak() {
                console.log('doctor');
            }
        }
        const doctor = new Doctor();
        doctor.speak()
    </script>
</body>

</html>